package com.logica.mdm.webfrontend.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * Bean used to create query and initialize params
 *
 */
public class RequestWithParamsBean {

	/**
	 *  Map containing parameters 
	 *  After the first request add the number
	 *  of records to return and the first record 
	 *  to return
	 */
	private Map<String, Object> params;
	
	/** SQL Query **/
	private String searchQuery;
	
	/** Order by clause **/
	private String sortCriteria;
	
	public RequestWithParamsBean() {
		//Empty constructor
	}

	/**
	 * @return the params
	 */
	public Map<String, Object> getParams() {
		if (params == null) {
			params = new HashMap<String, Object>();
		}
		return params;
	}

	/**
	 * @param params the params to set
	 */
	public void setParams(Map<String, Object> params) {
		this.params = params;
	}

	/**
	 * @return the searchQuery
	 */
	public String getSearchQuery() {
		return searchQuery;
	}

	/**
	 * @param searchQuery the searchQuery to set
	 */
	public void setSearchQuery(String searchQuery) {
		this.searchQuery = searchQuery;
	}

	/**
	 * @return the sortCriteria
	 */
	public String getSortCriteria() {
		return sortCriteria;
	}

	/**
	 * @param sortCriteria the sortCriteria to set
	 */
	public void setSortCriteria(String sortCriteria) {
		this.sortCriteria = sortCriteria;
	}

	/**
	 * Set the index of the last record to return
	 * (If the parameter does'nt exists, add it)
	 * @param lastRecord
	 */
	public void setLastRecord(int lastRecord) {
		if (params == null) {
			params = new HashMap<String, Object>();
		}
		params.put("endRowNum", Integer.valueOf(lastRecord));
	}
	
	
	/**
	 * Set the index of the first record to return
	 * (If the parameter does'nt exists, add it)
	 * @param firstRecord
	 */
	public void setFirstRecord(int firstRecord) {
		if (params == null) {
			params = new HashMap<String, Object>();
		}
		params.put("startRowNum", Integer.valueOf(firstRecord));
	}
}
